<?php
/**
 * Created by PhpStorm.
 * User: zhangrxiang
 * Date: 2017/6/29
 * Time: 22:59
 */


class ZingSQLite extends SQLite3 {

	private $tab = '';
	function __construct( $filename,$tab ) {
		$flags          = null;
		$encryption_key = null;
		$this->tab      = $tab;
		$this->open($filename);
	}

	/**
	 * @return mixed
	 */
	public function lastInsertRowID() {
		$sql = "SELECT ID FROM COMPANY ORDER BY ROWID DESC LIMIT 1;";
		return $this->querySingle($sql);
	}

	/**
	 * @return bool
	 */
	public function tableExist() {
		$sql = "SELECT COUNT(*) FROM sqlite_master WHERE `type`='table' AND `name`='".$this->tab."'";
		return (bool)$this->querySingle($sql);
	}

	public function queryAll() {
		$sql = "SELECT * FROM ".$this->tab;
		return $this->query($sql);
	}

}

$db = new ZingSQLite('test.db','COMPANY');
$all = $db->queryAll();
$allArr = $all->fetchArray();
echo count($allArr);
//foreach ($allArr as $item => $value){
//	echo $item;
//}
